<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

$controller->loadClass('Feedback');
$controller->loadClass('FeedbackModel');

// initialize objects
$rq =& new RequestData($_GET);
$rp =& new RequestData($_POST);
//$rp->setHtmlValues('body'); // to skip $_GET['body'] not strip html

$obj = new Feedback;

$manager =& $obj->setManager(new FeedbackModel());
$manager->checkPriv($priv, $controller->action, @$rq->id);


switch ($controller->action) {
case 'delete': // ------------------------------
	 
	$manager->delete($rq->id);
	$controller->go();

	break;
	
	
case 'answer_status': // ------------------------------
	 
	$manager->status($rq->status, $rq->id, 'answered');
	$controller->go();

	break;	
	
	
case 'place_status': // ------------------------------
	 
	$manager->status($rq->status, $rq->id, 'placed');
	$controller->go();

	break;
	
	
case 'file': // --------------------------------
	 
	$data = &$manager->getById($rq->id);
	$manager->sendFileDownload($data, $rq->f);
	exit;

	break;	
	
	
case 'answer': // ------------------------------

	$data = array();
	
	if(isset($rp->submit)) {
		
		$is_error =& $obj->validate($rp->vars);
		
		if($is_error) {
			$rp->stripVars(true);
			$obj->set($rp->vars);
			$data = &$rp->vars;
		
		} else {
			$rp->stripVars('stripslashes');
			$sent = $manager->sendAnswer($rp->vars);
			
			if(!$sent) {
				$rp->stripVars(true);
				$obj->set($rp->vars);	
				$obj->setError('email_not_sent');
				$data = &$rp->vars;
			
			} else {
				$rp->stripVars('addslashes');
				$obj->set($rp->vars);

				$manager->setEntryAnswered($rq->id, $obj->get());
				$controller->go();				
			}
		}
	
	} else {
		$data = &$manager->getById($rq->id);
		$data = &$rp->stripVarsValues($data);
		$obj->set($data);	
	}
	
	
	$view = &$controller->getView($obj, $manager, 'FeedbackView_form', $data);

	break;


default: // ------------------------------------
	
	$view = &$controller->getView($obj, $manager, 'FeedbackView_list');
}
?>